// -*- coding: utf-8 -*-
#include "diffhighlighter.h"

DiffHighlighter::DiffHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent)
{
    // 设置差异行的高亮格式
    m_diffFormat.setBackground(Qt::yellow);
    m_diffFormat.setForeground(Qt::black);
}

void DiffHighlighter::setHighlightLines(const QList<int> &lines)
{
    m_highlightLines = lines;
    rehighlight();
}

void DiffHighlighter::clearHighlight()
{
    m_highlightLines.clear();
    rehighlight();
}

void DiffHighlighter::highlightBlock(const QString &text)
{
    Q_UNUSED(text);
    
    // 获取当前块的行号
    int currentBlockNumber = currentBlock().blockNumber();
    
    // 检查是否需要高亮
    if (m_highlightLines.contains(currentBlockNumber)) {
        setFormat(0, text.length(), m_diffFormat);
    }
}